<template>
  <div class="block" v-loading="loading">
    <el-button size="small" @click="firstDraft" type="primary">
      <a :download="value1">下载</a>
    </el-button>
    <el-button size="small" style="float:right" @click="$router.back(-1)">返回</el-button>
    <el-input class="mt" type="textarea" :rows="10" placeholder="请输入意见" v-model="doc"></el-input>
    <div class="date">
      <el-date-picker
        value-format="yyyy-MM-dd HH:mm:ss"
        format="yyyy-MM-dd HH:mm:ss"
        v-model="date"
        type="date"
        placeholder="选择日期"
      ></el-date-picker>
      <el-button @click="submit" class="button">提交</el-button>
    </div>
  </div>
</template>
<script>
import { getToken } from "@/utils/auth";
import request from "@/utils/request";
export default {
  data() {
    return {
      loading: false,
      date: "",
      view: "",
      itemid: "",
      doc: "",
      date: "",
      filename: [{ name: "" }],
      token: { token: getToken() },
      p: {
        file: 1
      },
      value1: ""
    };
  },
  created() {
    this.host = this.$host;
    this.itemid = this.$route.query.id;
    this.getdoc();
    console.log(getToken());
  },
  methods: {
    getdoc() {
      var that = this;
      request(`/opinion/selectdocurl`, {
        method: "get",
        headers: {
          "Content-Type": "application/json"
        },
        params: { itemId: that.itemid }
      })
        .then(res => {
          console.log(res);
          that.value1 = res.data.object;
        })
        .catch(e => {
          console.log(e);
        });
    },
    submit() {
      this.loading = true;
      var that = this;
      console.log(this);
      var resdata = {
        reportDate: that.date,
        opinion: that.doc,
        itemId: that.itemid
      };
      console.log(resdata);
      request(`/opinion/fristsumbit`, {
        method: "post",
        headers: {
          "Content-Type": "application/json"
        },
        data: resdata
      })
        .then(res => {
          that.loading = false;
          console.log(res);
          if (res.data.code == 1) {
            that.$message.success(res.data.message);
            setTimeout(() => {
              that.$router.go(-1); //返回上一层
            }, 500);
          } else {
            that.$message.error(res.data.message);
          }
        })
        .catch(e => {
          that.loading = false;
          console.log(e);
        });
    },

    firstDraft() {
      var that = this;
      var host = this.$host;
      location.href = `${host}download?fileurl=${that.value1}`;
    }
  }
};
</script>

<style scoped>
.mt {
  margin-top: 37px;
}
.uploader-drop {
  border: 1px solid#ccc !important;
}
.button {
  margin-top: 50px;
  display: block;
}
.date {
  margin-top: 45px;
}
.block {
  width: 565px;
  margin: 50px 80px;
  padding: 46px;
  box-shadow: 0 0 10px #dacece;
}
</style>